package com.nineclock.sign.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;

import com.nineclock.sign.dto.SignDto;
import com.nineclock.sign.dto.SignInfoDTO;

import com.nineclock.sign.dto.StatisticsTeamSignInDto;
import com.nineclock.sign.service.SignInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@Api(value = "签到接口", tags = "签到服务")
public class SignInfoController {
    @Autowired
    private SignInfoService signInfoService;

    /**
     * 接口名称：APP: 签到
     * 接口路径：POST/sign/insert
     */
    @PostMapping("/insert")
    public Result sign(SignInfoDTO signInfoDTO) {
        signInfoService.sign(signInfoDTO);
        return Result.success();
    }
    /**
     * 查询签到列表
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param page      总页数
     * @param pageSize  当前页大小
     * @return
     */
    @GetMapping("/sign")
    @ApiOperation("查询签到列表")
    public Result<PageResult<List<SignDto>>> querySigns(@RequestParam String startTime, @RequestParam String endTime, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize){
        PageResult<List<SignDto>> signInfoDtoList = signInfoService.querySigns(startTime,endTime,page,pageSize);
        return Result.success(signInfoDtoList);
    }
    /**
     * APP: 获取团队员工打卡列表
     * 接口路径：GET/sign/listSignAllUser
     */
    @GetMapping("listSignAllUser")
    @ApiOperation("获取团队员工打卡列表")
    public Result<List<StatisticsTeamSignInDto>> listSignAllUser(String dateStr){
        List<StatisticsTeamSignInDto> statisticsTeamSignInDtos = signInfoService.listSignAllUser(dateStr);
        return Result.success(statisticsTeamSignInDtos);
    }



    /*接口名称：APP: 获取当前用户当天签到次数
     *  接口路径：GET/sign/getDayCount
     */
    @GetMapping("getDayCount")
    public Result queryDaySign(){
        int daySign = signInfoService.queryDaySign();
        return Result.success(daySign);
    }

    /*APP: 查询本月签到记录
        接口路径：GET/sign/pagingSignCurrentUserByMonth
        */
    @GetMapping("pagingSignCurrentUserByMonth")
    public Result<List<SignInfoDTO>> queryMonthSign(String dateStr ){
        List<SignInfoDTO> signInfoDTOS = signInfoService.queryMonthSign( dateStr);

        return Result.success( signInfoDTOS );
    }

    /**
     *接口路径：
     * GET/sign/export
     */
    @GetMapping("/export")
    public void exportSignData(String startTime, String endTime) throws IOException {
        signInfoService.exportSignData(startTime,endTime);
    }
}
